var ajax = require('../../utils/ajax.js');
var util = require('../../utils/util.js');
var common = require('../../utils/common.js');

Page({
  data: {
    selectList: ['我要开店', '系统BUG', '建议'],
    selectedIndex: 0,
    phone: '',
    content: '',
  },

  onLoad() {
    var _self = this;

    ajax.G('/openapi/CHome/getOemInfo', {}, function(res) {
      var oem = res.result;

      wx.setNavigationBarTitle({
        title: oem.title,
      });

      _self.setData({
        oem
      });
    });
  },

  _selectQuesTy: function(e) {
    this.setData({
      selectedIndex: e.detail.value
    });
  },

  _phoneChange: function(e) {
    this.setData({
      phone: e.detail.value
    });
  },

  _contentChange: function(e) {
    this.setData({
      content: e.detail.value
    });
  },

  _submit: function() {
    if (this.data.selectedIndex == 0) {
      return util.alert('请选择你的问题类型');
    }
    if (!this.data.phone) {
      return util.alert('请输入你的手机号');
    }
    if (!this.data.content) {
      return util.alert('请输入你的问题描述');
    }
    ajax.P('/openapi/CHome/addFeedBack', {
      phone: this.data.phone,
      type: this.data.selectedIndex,
      content: this.data.content,
    }, function(data) {
      util.alert('谢谢您的支持！您的反馈我们会尽快处理！', function() {
        wx.switchTab({
          url: '../index/index'
        });
      });
    });
  },


  //打电话
  _call(evt) {
    var phone = evt.currentTarget.dataset.val;
    var formId = evt.detail.formId;

    wx.makePhoneCall({
      phoneNumber: phone
    });
    common.submitForm(formId);
  },

  //复制
  _copy(evt) {
    var val = evt.currentTarget.dataset.val;
    var formId = evt.detail.formId;
    wx.setClipboardData({
      data: val,
      success: function(res) {
        wx.getClipboardData({
          success: function(res) {
            util.showOK('咨询微信号复制成功');
          }
        })
      }
    })
    common.submitForm(formId);
  }


});